package com.library.entity;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;


/*
* 图书类
* */

@Entity
@Table(name="book")
public class Book {
	private Integer bookId;		//图书ID
	private String ISBN;
	private String name;			//图书名称
	private String author;		//作者
	private String publish;		//出版社
	private BookClass bookClass;		//图书类别
	private Float grade;		//图书评分
	private String bookImage;		//封面图片
	private Integer borrowTimes;	//借阅次数
	private Integer browseTimes;	//浏览次数
	private float price;		   //价格
	private Integer state;		//状态	0在库 1借出 2丢失
	private Set<Evaluate> evaluates =new HashSet<Evaluate>();	//评论
	private Set<Borrow> borrows =new HashSet<Borrow>();	//借阅单
	private Set<Payment> payments =new HashSet<Payment>();	//缴费单
	private Set<Collection> collections = new HashSet<>();	//收藏夹
	private Set<Staff> staffs	= new HashSet<>();
	private Set<RecommendBook> recommendBooks = new HashSet<>();
	private Set<BookRelation> bookRelationsOne = new HashSet<>();
	private Set<BookRelation> bookRelationsTwo = new HashSet<>();

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getBookId() {
		return bookId;
	}
	public void setBookId(Integer bookId) {
		this.bookId = bookId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getPublish() {
		return publish;
	}

	public void setPublish(String publish) {
		this.publish = publish;
	}

	public Float getGrade() {
		return grade;
	}

	public void setGrade(Float grade) {
		this.grade = grade;
	}

	public String getBookImage() {
		return bookImage;
	}

	public void setBookImage(String bookImage) {
		this.bookImage = bookImage;
	}


	@ManyToOne(cascade=CascadeType.PERSIST)
	@JoinColumn(name="bookClassId")
	public BookClass getBookClass() {
		return bookClass;
	}
	public void setBookClass(BookClass bookClass) {
		this.bookClass = bookClass;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name="bookId")                       //指定与本类主键所对应的外表的外键
	public Set<Evaluate> getEvaluates() {
		return evaluates;
	}

	public void setEvaluates(Set<Evaluate> evaluates) {
		this.evaluates = evaluates;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name="bookId")                       //指定与本类主键所对应的外表的外键
	public Set<Borrow> getBorrows() {
		return borrows;
	}

	public void setBorrows(Set<Borrow> borrows) {
		this.borrows = borrows;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name="bookId")                       //指定与本类主键所对应的外表的外键
	public Set<Payment> getPayments() {
		return payments;
	}

	public void setPayments(Set<Payment> payments) {
		this.payments = payments;
	}

	public String getISBN() {
		return ISBN;
	}

	public void setISBN(String ISBN) {
		this.ISBN = ISBN;
	}

	public Integer getBorrowTimes() {
		return borrowTimes;
	}

	public void setBorrowTimes(Integer borrowTimes) {
		this.borrowTimes = borrowTimes;
	}

	public Integer getBrowseTimes() {
		return browseTimes;
	}

	public void setBrowseTimes(Integer browseTimes) {
		this.browseTimes = browseTimes;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	@ManyToMany(cascade=CascadeType.PERSIST)
	@JoinTable(
			name="collectionbookall",
			joinColumns={@JoinColumn(name="bookId")},
			inverseJoinColumns={@JoinColumn(name="collectionId")})
	public Set<Collection> getCollections() {
		return collections;
	}

	public void setCollections(Set<Collection> collections) {
		this.collections = collections;
	}

	@ManyToMany(cascade=CascadeType.PERSIST)
	@JoinTable(
			name="staffbookall",
			joinColumns={@JoinColumn(name="bookId")},
			inverseJoinColumns={@JoinColumn(name="staffId")})
	public Set<Staff> getStaffs() {
		return staffs;
	}

	public void setStaffs(Set<Staff> staffs) {
		this.staffs = staffs;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name="bookId")                       //指定与本类主键所对应的外表的外键
	public Set<RecommendBook> getRecommendBooks() {
		return recommendBooks;
	}
	public void setRecommendBooks(Set<RecommendBook> recommendBooks) {
		this.recommendBooks = recommendBooks;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name ="book1Id")
	public Set<BookRelation> getBookRelationsOne() {
		return bookRelationsOne;
	}
	public void setBookRelationsOne(Set<BookRelation> bookRelationsOne) {
		this.bookRelationsOne = bookRelationsOne;
	}

	@OneToMany(cascade=CascadeType.PERSIST,orphanRemoval = true)            //指定一对多关系
	@JoinColumn(name ="book2Id")
	public Set<BookRelation> getBookRelationsTwo() {
		return bookRelationsTwo;
	}
	public void setBookRelationsTwo(Set<BookRelation> bookRelationsTwo) {
		this.bookRelationsTwo = bookRelationsTwo;
	}
}
